home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Goodies / AutoGuest / NoInteractionPatch.a < prev    next >
Text File  |  1991-10-16  |  2KB  |  108 lines

  1. ;;
  2. ;;  'No User Interaction'-avoidance Patch by Greg Anderson and Michael Gough
  3. ;;
  4. ;;  17 September 1991
  5. ;;
  6. ;;
  7.  
  8.     CASE        ON
  9.     
  10.     INCLUDE        'Traps.a'
  11.     INCLUDE        'PPCToolbox.a'
  12.  
  13.  
  14.     SEG            'NoInteraction'
  15.  
  16. ;
  17. ; Our patch skips over the following code:
  18. ;
  19. ;        if( EvilBackGroundTestIsTrue )
  20. ;        {
  21. ;            DisposeHandle( workInProgress );
  22. ;            *errorResult = eNoUserInteractionAllowed;
  23. ;            return(0);
  24. ;        }
  25. ;
  26. ; To do this, we first intercept all
  27. ; calls to DisposHandle:
  28. ;
  29.  
  30. DisposePatch            PROC        EXPORT
  31.  
  32.         EXPORT            OldDisposeAddress
  33.         
  34.         movem.l            a1, -(sp)
  35.  
  36. ;
  37. ; First we do a little bit of sanity checking to make
  38. ; sure that the dispatcher that called us looks like
  39. ; the dispatcher we expect to see
  40. ;
  41. ; 205F225F == move.l (sp)+,A0 followed by move.l (sp)+,A1
  42. ;
  43.  
  44. DispatcherReturnAddressOffset    EQU    4
  45.  
  46.         move.l        DispatcherReturnAddressOffset(sp), a1
  47.         cmpi.l        #$205F225F, (a1)
  48.         bne.s        DefaultDispose
  49.         
  50. ;
  51. ; Then we look for the 'eNoUserInteractionAllowed'
  52. ; opcode (sp+20 is the return address)
  53. ;
  54.  
  55. ATrapReturnAddressOffset    EQU        $20
  56.  
  57. ;
  58. ; The above C code looks like this once compiled:
  59. ;
  60. ;                        _DisposeHandle
  61. ;            sp+20 ->    movea.l        $10(a6),a0            (4 bytes)
  62. ;                        move.w        #$FD9E,(a0)            (4 bytes)
  63. ;                        moveq        #0, d0                (2 bytes)
  64. ;                        bra            exit                (4 bytes)
  65. ;                                                        ---------
  66. ;                                                        14 bytes
  67. ;
  68.         
  69.         move.l        ATrapReturnAddressOffset(sp), a1
  70.         cmpi.w        #$FD9E, 6(a1)
  71.         bne.s        DefaultDispose
  72.  
  73. ;
  74. ; To disable this code, we
  75. ;
  76. ;        (a)        do not fall through to DisposeHandle
  77. ;        (b)        skip the code that returns eNoUserInteractionAllowed
  78. ;                by adding a constant (14 decimal) to the return address
  79. ;
  80.                                                 
  81.         add            #14, a1
  82.         move.l        a1, ATrapReturnAddressOffset(sp)
  83.  
  84. ;
  85. ; Prepare to return to the trap dispatcher
  86. ;
  87.                     
  88.         movem.l        (sp)+, a1
  89.         move.l        #0, d0
  90.         
  91.         rts
  92.  
  93. DefaultDispose:
  94.         
  95.         movem.l        (sp)+, a1
  96.                     
  97. BackToDispose:
  98.  
  99.         move.l        OldDisposeAddress, -(sp)
  100.         rts
  101.         
  102. OldDisposeAddress
  103.  
  104.         dc.l        1
  105.  
  106.  
  107.         END
  108.